<?
include("./_common.php");
include("$g4[path]/_head.php");


$shop = get_shop();
$goods_dir = $g4[path]."/data/goods/";

if(!$Type || $Type == ""){$Type = "1";}


if($CODE!="")
{
	$category_info = get_category($CODE);
	if($category_info[c_depth] == "0")
	{
		$sub_cate_sql = "select * from g4_category where c_pcode = '".$CODE."'";
		$sub_cate_rst = mysql_query($sub_cate_sql);
		$tmp_cate = array();
		while($sub_cate = mysql_fetch_array($sub_cate_rst))
		{
			$tmp_cate[] = $sub_cate[c_code];
		}

		if(count($tmp_cate))
		{
			$join_cate = implode("|",$tmp_cate);
			$cate_where = " and c_code REGEXP '".$join_cate."' ";
		}
		else
		{
			$cate_where = " and c_code='".$CODE."' ";
		}
	}
	else
	{
		$cate_where = " and c_code='".$CODE."' ";
	}
}

if($search_str!="")
{
	$search_where = " and concat(g_name,g_info,g_create,g_nation,g_content) like '%".$search_str."%' ";
}


$goods_sql = "select g_code from g4_goods where 1 ".$cate_where.$search_where;

if (!$sst){$sst  = "idx";$sod = "desc";}

$goods_sql.= " order by $sst $sod ";

$total_count = mysql_num_rows(mysql_query($goods_sql));

switch($Type)
{
	case "1":{$rows = 10;break;}
	case "2":{$rows = 16;break;}
	case "3":{$rows = 1;break;}
	default:{$rows = 10;}
}

$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함

$goods_sql.=" limit $from_record, $rows";
$goods_rst = mysql_query($goods_sql);

$pagelist = get_paging("5", $page, $total_page, "$_SERVER[PHP_SELF]?CODE=$CODE&Type=$Type&search_str=$search_str$qstr&page=");

if(!$pagelist || $pagelist==""){$pagelist = "1";}
?>
<link rel="stylesheet" href="<?=$g4['path']?>/shop/style.css" type="text/css">
<script language="javascript" src="<?=$g4['path']?>/shop/shop.js"></script>
<table cellpadding="0" cellspacing="0" border="0" width="100%">
	<tr height="25">
		<td><?include("goods_list_head.php");?></td>
	</tr>
	<tr><td height="1" bgcolor="#D7D7D7"></td></tr>
	<tr>
		<td>
<?
	while($goods_row = mysql_fetch_array($goods_rst))
	{
		$goods = get_goods($goods_row[g_code]);
		include("goods_list.".$Type.".skin.php");
	}
	if($total_count == "0"){echo("<table cellpadding='0' cellspacing='0' border='0' width='100%' height='100' style='border-bottom:solid 1px #D7D7D7'><tr><td align='center'>등록된 상품이 없습니다.</td></tr></table>");}
?>
		</td>
	</tr>
	<?if($Type=="2"){?><tr><td height="1" bgcolor="#D7D7D7"></td></tr><?}?>
	<tr height="40">
		<td align="center"><?=$pagelist?></td>
	</tr>
</table>
<?
include("$g4[path]/_tail.php");
?>